<%--
  Created by IntelliJ IDEA.
  User: wyp
  Date: 2020/5/12
  Time: 8:23
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta name="renderer" content="webkit|ie-comp|ie-stand">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width,user-scalable=yes, minimum-scale=0.4, initial-scale=0.8,target-densitydpi=low-dpi" />
    <meta http-equiv="Cache-Control" content="no-siteapp" />
    <!--引入JQuery，必须要在bootstrap.js之前引入-->
    <script type="text/javascript" src="./resources/js/jquery-3.4.1.min.js"></script>
    <link rel="stylesheet" href="./resources/css/font.css">
    <link rel="stylesheet" href="./resources/css/xadmin.css">
    <!-- <link rel="stylesheet" href="./css/theme5.css"> -->
    <script src="./resources/lib/layui/layui.js" charset="utf-8"></script>
    <script type="text/javascript" src="./resources/js/xadmin.js"></script>
    <title>公司编辑</title>
</head>
<body>
<script>
    $(document).ready(function () {
        // 获取地址栏id
        var companyId = getQueryVariable("companyId");
        getCompanyInfo(companyId);
    });

    // 获取地址栏参数
    function getQueryVariable(variable)
    {
        var query = window.location.search.substring(1);
        var vars = query.split("&");
        for (var i=0;i<vars.length;i++) {
            var pair = vars[i].split("=");
            if(pair[0] == variable){return pair[1];}
        }
        return(false);
    }

    //根据id查找景点信息
    function getCompanyInfo(companyId) {
        $.ajax({
            type: "POST",
            dataType: "json",
            data:{"method":"companyFind","companyId":companyId},
            url:"./companyControl",
            success:function (data) {
                console.log(data.spotName);
                document.getElementById("companyId").value = data.companyId;
                document.getElementById("companyName").value = data.companyName;
            }
        });
    }
    
    //更新景点

    layui.use(['form', 'layer','jquery'],
        function() {
            $ = layui.jquery;
            var form = layui.form,
                layer = layui.layer;


            //监听提交
            form.on('submit(companyUpdate)',
                function(data) {
                    console.log(data);
                    //发异步，把数据提交给后台
                    var companyId = $('#companyId').val();
                    var companyName = $('#companyName').val();
                    console.log("companyUpdate测试");

                    $.ajax({
                        type:"POST",
                        dataType: "json",
                        url:"./companyControl",
                        data:{"method":"companyEdit","companyId":companyId,"companyName":companyName},
                        success:function(data){
                            layer.alert("更新成功", {
                                    icon: 6
                                },
                                function() {
                                    // 获得frame索引
                                    var index = parent.layer.getFrameIndex(window.name);
                                    //关闭当前frame
                                    parent.layer.close(index);
                                    xadmin.father_reload();
                                });
                        }
                    });
                    return false;
                });

        });
    function updataSpot() {


    }
</script>
<%--用来存储companyId--%>
<input type="text" style="display: none" id="companyId" name="companyId">
    <div class="layui-fluid">
        <div class="layui-row">
            <form class="layui-form">
                <div class="layui-form-item">
                    <label for="companyName" class="layui-form-label">
                        <span class="x-red">*</span>公司名称
                    </label>
                    <div class="layui-input-inline">
                        <input type="text" id="companyName" name="companyName" required="" lay-verify="required"
                               autocomplete="off" class="layui-input">
                    </div>
                </div>


                <div class="layui-form-item">
                    <label for="companyName" class="layui-form-label">
                    </label>
                    <button  class="layui-btn" lay-filter="companyUpdate" lay-submit="" >
                        修改
                    </button>
                </div>


            </form>
        </div>
    </div>
</body>
</html>
